package com.tcu.part.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tcu.part.entity.PartNum;
import com.tcu.part.mapper.PartNumMapper;
import com.tcu.part.service.IPartNumService;
import org.springframework.stereotype.Service;

@Service
public class PartNumServiceImpl extends ServiceImpl<PartNumMapper, PartNum> implements IPartNumService {

    @Override
    public Boolean updateNumber(String partId, Integer num) {
        PartNum partNum = baseMapper.selectById(partId);
        partNum.setNum(num);
        baseMapper.updateById(partNum);
        return true;
    }

    @Override
    public void consumePart(String partId, Integer consumeNum) {
        PartNum partNum = baseMapper.selectById(partId);
        partNum.setNum(partNum.getNum()-consumeNum);
        baseMapper.updateById(partNum);
    }

    @Override
    public void rollBackPart(String partId, Integer consumeNum) {
        PartNum partNum = baseMapper.selectById(partId);
        partNum.setNum(partNum.getNum()+consumeNum);
        baseMapper.updateById(partNum);
    }

}
